package com.ruoyi.web.controller.dwxController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.controller.utils.HttpUtils;
import com.ruoyi.web.domain.ExecutionRecord;
import com.ruoyi.web.domain.ExecutionRecordDetails;
import com.ruoyi.web.domain.ExecutionSuccess;
import com.ruoyi.web.service.*;
import org.apache.catalina.User;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/*2025-03-10 针对维信金科新系统变更自动扣款系统*/
@RestController
@RequestMapping("/api/new")
public class NewJointController {

    @Resource
    private IExecutionRecordService executionRecordService;

    @Resource
    private IExecutionRecordDetailsService executionRecordDetailsService;

    @Resource
    private IExecutionSuccessService executionSuccessService;

    /*
     * 获取到全部的业务号
     * */
    public JSONArray getWorkList1(String cookie, String bid) {
        String url = "https://vcspro.vcredit.com/vcspro-api/task/list?actionType=ownerTaskList";

        HashMap<String, Object> paramsHashMap = new HashMap<>();
        paramsHashMap.put("current", 1);
        paramsHashMap.put("size", 1000);
        paramsHashMap.put("folderId", "0");

        // 根据订单号bid查询
        if (!Objects.isNull(bid) && !"".equals(bid)) {
            paramsHashMap.put("bid", bid);
        }
        String s = HttpUtils.sendPostForJson(url, cookie, paramsHashMap);

        Map<String, Object> resultMap = JSONObject.parseObject(s).getInnerMap();
        JSONObject data = (JSONObject) resultMap.get("data");
        JSONArray jsonArray = (JSONArray) data.get("records");

        /* 获取当前账户的订单总数 total
         * 会有total传入值为double的情况 例311.0
         * */
        //int total = Integer.parseInt(String.valueOf(data.get("total")));
        int total = (int) Double.parseDouble(String.valueOf(data.get("total")));
        if (total / 1000 != 0) {
            for (int i = 0; i < total / 1000; i++) {

                HashMap<String, Object> newparams = new HashMap<>();
                newparams.put("current", i + 2);
                newparams.put("size", 1000);
                paramsHashMap.put("folderId", "0");

                String newS = HttpUtils.sendPostForJson(url, cookie, newparams);
                Map<String, Object> newResultMap = JSONObject.parseObject(newS).getInnerMap();
                JSONObject newdata = (JSONObject) newResultMap.get("data");
                jsonArray.addAll((JSONArray) newdata.get("records"));

            }
        }
        return jsonArray;
    }

    /*扣款接口*/
    public JSONObject handelDeduct(String Bid, String Amount, String cookie, String apiToken) {
        String url = "https://vcspro.vcredit.com/vcspro-api/deductOperation?actionType=handleDeduct";

        HashMap<String, Object> paramsMap = new HashMap<>();
        paramsMap.put("amount", Amount);
        paramsMap.put("bid", Bid);
        paramsMap.put("scene", "orderDeduct");
        paramsMap.put("apiToken", apiToken);

        String s = HttpUtils.sendPostForJson(url, cookie, paramsMap);
        JSONObject resultMap = JSONObject.parseObject(s);
        return resultMap;

    }

    /*
     * 根据案件号(之前为业务Id) 查询扣款执行结果
     * 只获取时间最近的一条
     * */
    public JSONObject checkExecute(String caseNo, String cookie, String apiToken) {
        String url = "https://vcspro.vcredit.com/vcspro-api/task/list?actionType=queryDeductRecord";
        HashMap<String, Object> params = new HashMap<>();
        params.put("caseNo", caseNo);
        params.put("apiToken", apiToken);
        params.put("current", 1);
        params.put("size", 3);
        String s = HttpUtils.sendPostForJson(url, cookie, params);
        JSONObject resultMap = JSONObject.parseObject(s);

        return resultMap;
    }

    /*
     * 获取当前订单号最后一次扣款时间(流水账视图)
     * */
    public Date taskDetail(String Bid, String cookie) throws ParseException {
        String url = "https://vcspro.vcredit.com/vcspro-api/task/detail?actionType=orderDetail";
        HashMap<String, Object> params = new HashMap<>();
        params.put("bid", Bid);

        String s = HttpUtils.sendPostForJson(url, cookie, params);
        JSONObject resultMap = JSONObject.parseObject(s);

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date receivedTime = null;

        if ("0000".equals(String.valueOf(resultMap.get("code")))) {
            if (!Objects.isNull(resultMap.get("data"))) {
                JSONObject data = (JSONObject) resultMap.get("data");
                JSONArray accountViewList = (JSONArray) data.get("accountViewList");
                if (!Objects.isNull(accountViewList)) {

                    JSONObject result = accountViewList.stream()
                            .filter(obj -> obj instanceof JSONObject)  // 确保是JSONObject
                            .map(obj -> (JSONObject) obj)
                            .filter(json -> json.getString("receivedTime") != null)
                            .findFirst()
                            .orElse(new JSONObject());

                    if (!Objects.isNull(result) && !Objects.isNull(result.get("receivedTime"))) {
                        receivedTime = sdf.parse(String.valueOf(result.get("receivedTime")));
                    }

                }
            }
        }

        return receivedTime;
    }

    /*获取催记联络人*/
    public JSONObject queryPhoneDirectory(String apiToken, String caseNo, String custId, String cookie) {
        String url = "https://vcspro.vcredit.com/vcspro-api/task/list?actionType=queryPhoneDirectory";
        HashMap<String, Object> params = new HashMap<>();

        /*custId可能传入的数据为 3.45926E+7*/
        double custIdDouble = Double.parseDouble(custId);
        custId = String.valueOf(Math.round(custIdDouble));

        params.put("apiToken", apiToken);
        params.put("caseNo", caseNo);
        params.put("current", 1);
        // 后续可能会有时间排序逻辑，暂为5
        params.put("pageSize", 5);
        params.put("custId", custId);
        params.put("mode", "collect");
        String s = HttpUtils.sendPostForJson(url, cookie, params);
        JSONObject resultMap = JSONObject.parseObject(s);

        if ("0000".equals(resultMap.get("code")) && !Objects.isNull(resultMap.get("data"))) {
            JSONObject data = (JSONObject) resultMap.get("data");
            JSONArray records = (JSONArray) data.get("records");
            if (!Objects.isNull(records)) {
                return (JSONObject) records.get(0);
            }
        }
        return null;
    }

    /*发送催记*/
    public JSONObject collActionManage(HashMap<String, Object> params, String cookie) {
        String url = "https://vcspro.vcredit.com/vcspro-api/collAction/manage?actionType=add";
        String s = HttpUtils.sendPostForJson(url, cookie, params);
        JSONObject resultMap = JSONObject.parseObject(s);
        return resultMap;
    }


    /*扣款接口*/
    @RequestMapping("/deductionMain")
    public AjaxResult deductionMain(String cookie, String Amount) throws ParseException, InterruptedException {

        AjaxResult ajaxResult = new AjaxResult();

        /*拦截非正常扣款金额*/
        if (!Amount.matches("^[0-9]*$")) {
            ajaxResult.put("code", "500");
            ajaxResult.put("msg", "请输入正确的金额！");
            return ajaxResult;
        }

        /*默认为100元*/
        if (Objects.isNull(Amount) || "".equals(Amount)) {
            Amount = "100";
        }

        //获取当前登录用户 ---> 自动化程序登录用户
        String loginName = ShiroUtils.getSysUser().getLoginName();

        //清空表
        executionRecordDetailsService.truncateTable(loginName);

        ExecutionRecord executionRecord = new ExecutionRecord();

        /*成功条数*/
        long successTotal = 0;
        /*失败条数*/
        long failTotal = 0;
        //执行列表
        JSONArray workList1 = null;

        //获取工作台任务列表
        try {
            workList1 = this.getWorkList1(cookie, null);
        } catch (Exception e) {
            e.printStackTrace();
            ajaxResult.put("code", "500");
            ajaxResult.put("msg", "获取用户列表数据失败，请联系管理员！");
            return ajaxResult;
        }

        //当执行任务列表是有效数据时
        if (!Objects.isNull(workList1)) {
            System.out.println("此账号一共查询到" + workList1.size() + "条数据");
            System.out.println("本次扣款金额为:" + Amount + "元");

            /*执行任务列表总条数*/
            long total = workList1.size();
            executionRecord.setTotal(total);
            //保存执行记录
            executionRecordService.insertExecutionRecord(executionRecord);

            for (Object item : workList1) {
                //记录明细表
                ExecutionRecordDetails executionRecordDetails = new ExecutionRecordDetails();
                //任务对象
                JSONObject obj = (JSONObject) item;

                //业务id
                /*bid可能传入的数据为 3.45926E+7*/
                double bidDouble = Double.parseDouble(String.valueOf(obj.get("bid")));
                executionRecordDetails.setBusinessId(Math.round(bidDouble));
                String bid = String.valueOf(Math.round(bidDouble));
                //用户名称
                executionRecordDetails.setUserName(obj.get("custName") + "");
                //批次
                executionRecordDetails.setBatch(executionRecord.getId());
                //案件号
                executionRecordDetails.setCaseNo(obj.get("caseNo") + "");
                // apiToken
                executionRecordDetails.setApiToken(String.valueOf(obj.get("apiToken")));

                try {
                    //扣款操作
                    JSONObject jsonObject = this.handelDeduct(bid, Amount, cookie, String.valueOf(obj.get("apiToken")));
                    //扣款返回的信息
                    JSONObject data = (JSONObject) jsonObject.get("data");
                    if (Objects.isNull(data)) {
                        System.out.println(jsonObject.get("message") + "bid:" + bid + "apiToken:" + String.valueOf(obj.get("apiToken")));
                    } else {
                        Object msg = String.valueOf(data.get("msg"));
                        System.out.println(msg);
                    }

                    /*获取最后一次扣款成功时间*/
                    Date receivedTime = this.taskDetail(bid, cookie);
                    if (!Objects.isNull(receivedTime)) {
                        executionRecordDetails.setReceivedTime(receivedTime);
                    }

                    //当为true时记录成功
                    if (String.valueOf(jsonObject.get("message")).equals("请求成功")) {
                        successTotal++;
                        executionRecordDetailsService.insertExecutionRecordDetails(executionRecordDetails);
                    } else {
                        failTotal++;
                    }
                } catch (Exception e) {
                    ajaxResult.put("code", "500");
                    ajaxResult.put("msg", "扣款失败，请联系管理员！");
                    e.printStackTrace();
                }

                Thread.sleep(2000);
            }
            /*失败条数*/
            executionRecord.setFailTotal(failTotal);
            /*成功条数*/
            executionRecord.setSuccessTotal(successTotal);
            //更新执行记录 总的成功/失败条数
            executionRecordService.updateExecutionRecord(executionRecord);
            ajaxResult.put("code", "200");
            ajaxResult.put("msg", "批量申请成功，共计" + total + "条，申请成功" + successTotal + "条,申请失败" + failTotal + "条。");
            System.out.println("批量处理成功，共计" + total + "条，申请成功" + successTotal + "条,申请失败" + failTotal + "条。");
            return ajaxResult;
        } else {
            ajaxResult.put("code", "200");
            ajaxResult.put("msg", "获取任务数据为空，请核实是否存在任务数据！");
            return ajaxResult;
        }
    }

    /*获取扣款成功记录*/
    @RequestMapping("/screen")
    public AjaxResult screen(String cookie) {

        AjaxResult ajaxResult = new AjaxResult();

        ExecutionRecord executionRecord = new ExecutionRecord();

        /*获取到当前登录用户 ---> 自动化程序登录用户*/
        String loginName = ShiroUtils.getSysUser().getLoginName();

        //扣款成功条数
        long deductionSutotal = 0L;
        //扣款失败条数
        long deductionFautotal = 0L;

        long id = 0L;

        try {
            //清空当前表中的所有数据
//            executionSuccessService.truncateTable(loginName);

            //查询出所有的申请成功列表
            ExecutionRecordDetails executionRecordDetail = new ExecutionRecordDetails();
            executionRecordDetail.setCreateBy(loginName);
            List<ExecutionRecordDetails> executionRecordDetails = executionRecordDetailsService.selectExecutionRecordDetailsList(executionRecordDetail);

            if (executionRecordDetails.size() != 0) {
                //循环遍历每一条数据
                for (int i = 0; i < executionRecordDetails.size(); i++) {

                    id = executionRecordDetails.get(0).getBatch();

                    if (executionRecordDetails.get(i).getBusinessId() != null) {

                        ExecutionSuccess executionSuccess = new ExecutionSuccess();

                        JSONObject jsonObject = this.checkExecute(executionRecordDetails.get(i).getCaseNo(), cookie, executionRecordDetails.get(i).getApiToken());

                        String rspCode = (String) jsonObject.get("code") + "";
                        JSONObject data = (JSONObject) jsonObject.get("data");

                        if ("0000".equals(rspCode)) {
                            //获取扣款信息列表
                            JSONArray jsonArray = (JSONArray) data.get("records");

                            /* 获取当前订单号所有的扣款记录 */
                            for (int x = 0; x < jsonArray.size(); x++) {

                                //获取前三个扣款对象
                                JSONObject contentMap = (JSONObject) jsonArray.get(x);
                                /*获取扣款结果* */
                                String result = contentMap.get("statusDesc") + "";
                                /*获取结果说明* */
                                String resultDesc = contentMap.get("resultDesc") + "";
                                System.out.println("业务号：" + executionRecordDetails.get(i).getBusinessId() + "，扣款结果：" + result + "，扣款说明：" + resultDesc);
                                if (!result.equals("扣款失败")) {

                                    /*获取发送时间* */
                                    String cardNo = contentMap.get("sendTime") + "";
                                    /*获取扣款金额* */
                                    String amount = contentMap.get("amount") + "";

                                    /*获取扣款类型*/
                                    //String deductSourceOrigin = contentMap.get("deductSourceOrigin") + "";

                                    executionSuccess.setBusinessId(executionRecordDetails.get(i).getBusinessId());
                                    executionSuccess.setUserName(executionRecordDetails.get(i).getUserName());
                                    executionSuccess.setSendTime(cardNo);
                                    executionSuccess.setAmount(amount);
                                    executionSuccess.setResult(result);
                                    executionSuccess.setResultDesc(resultDesc);

                                    deductionSutotal++;
                                    executionSuccessService.insertExecutionSuccess(executionSuccess);
                                } else {
                                    deductionFautotal++;
                                }
                            }
                            System.out.println(executionRecordDetails.get(i).getBusinessId() + "--------------");
                        } else if ("0002".equals(rspCode)) {
                            System.out.println("bid:" + executionRecordDetails.get(i).getBusinessId() + "-->" + jsonObject.get("message"));
                            System.out.println("bid:" + executionRecordDetails.get(i).getBusinessId() + "apiToken:" + executionRecordDetails.get(i).getApiToken());
                            deductionFautotal++;
                        } else {
                            System.out.println("bid:" + executionRecordDetails.get(i).getBusinessId() + "-->" + jsonObject.get("message"));
                            System.out.println("bid:" + executionRecordDetails.get(i).getBusinessId() + "apiToken:" + executionRecordDetails.get(i).getApiToken());
                            deductionFautotal++;
                        }
                    }
                }

                /*
                 *更改主表中的扣款成功条数和失败次数
                 * */
                executionRecord.setId(id);
                //executionRecord.setDeductionFautotal(deductionFautotal);
                executionRecord.setDeductionSutotal(deductionSutotal);

                if (id != 0l) {
                    executionRecordService.updateExecutionRecord(executionRecord);
                }

            } else {
                ajaxResult.put("code", "200");
                ajaxResult.put("msg", "申请成功数据列表为空，请核实列表数据！");
                System.out.println("运行结束");
                return ajaxResult;
            }

            ajaxResult.put("code", "200");
            ajaxResult.put("msg", "查询成功，共计" + executionRecordDetails.size() + "条，扣款成功" + deductionSutotal + "条,扣款失败" + deductionFautotal + "条。");
            System.out.println("查询成功，共计" + executionRecordDetails.size() + "条，扣款成功" + deductionSutotal + "条,扣款失败" + deductionFautotal + "条。");
            return ajaxResult;
        } catch (Exception e) {
            e.printStackTrace();
            ajaxResult.put("code", "500");
            ajaxResult.put("msg", "获取用户列表数据失败，请联系管理员！");
            System.out.println("运行结束");
            return ajaxResult;
        }
    }

    /*使用EXCEL (业务ID)
     * 导入数据进行扣款操作
     * */
    @PostMapping("/importData")
    @ResponseBody
    public AjaxResult importData(MultipartFile file, @RequestParam("cookie") String cookie, @RequestParam("Amount") String Amount) throws Exception {
        AjaxResult ajaxResult = new AjaxResult();
        try {
            /*导入表格转换为List<User> 类型*/
            ExcelUtil<User> util = new ExcelUtil<User>(User.class);
            List<User> userList = util.importExcel(file.getInputStream());

            if (0 < userList.size()) {

                if (!Amount.matches("^[0-9]*$")) {
                    ajaxResult.put("code", "500");
                    ajaxResult.put("msg", "请输入正确的金额！");
                    return ajaxResult;
                }

                //获取当前登录用户 ---> 自动化程序登录用户
                String loginName = ShiroUtils.getSysUser().getLoginName();
                //清空表
                executionRecordDetailsService.truncateTable(loginName);

                ExecutionRecord executionRecord = new ExecutionRecord();
                /*成功条数*/
                long successTotal = 0;
                /*失败条数*/
                long failTotal = 0;
                //执行列表
                JSONArray workList1 = null;

                try {
                    workList1 = JSONArray.parseArray(JSON.toJSONString(userList));

                } catch (Exception e) {
                    e.printStackTrace();
                    ajaxResult.put("code", "500");
                    ajaxResult.put("msg", "获取用户列表数据失败，请联系管理员！");
                    return ajaxResult;
                }

                //当执行任务列表是有效数据时
                if (!Objects.isNull(workList1)) {
                    System.out.println("文件导入" + workList1.size() + "条数据");
                    System.out.println("本次扣款金额为:" + Amount + "元");

                    /*执行任务列表总条数*/
                    long total = workList1.size();
                    executionRecord.setTotal(total);
                    //保存执行记录
                    executionRecordService.insertExecutionRecord(executionRecord);

                    for (Object item : workList1) {
                        //记录明细表
                        ExecutionRecordDetails executionRecordDetails = new ExecutionRecordDetails();
                        //任务对象
                        JSONObject objDocument = (JSONObject) item;

                        // 业务落地更换 扣款需要 案件号caseNo 和 apiToken
                        // 需要重新查询当前业务id 获取相关信息
                        JSONArray objinfo = this.getWorkList1(cookie, String.valueOf(objDocument.get("businessId")));
                        JSONObject obj = (JSONObject) objinfo.get(0);

                        //业务id
                        /*bid可能传入的数据为 3.45926E+7*/
                        double bidDouble = Double.parseDouble(String.valueOf(obj.get("bid")));
                        executionRecordDetails.setBusinessId(Math.round(bidDouble));
                        String bid = String.valueOf(Math.round(bidDouble));
                        //用户名称
                        executionRecordDetails.setUserName(obj.get("custName") + "");
                        //批次
                        executionRecordDetails.setBatch(executionRecord.getId());
                        //案件号
                        executionRecordDetails.setCaseNo(obj.get("caseNo") + "");
                        // apiToken
                        executionRecordDetails.setApiToken(String.valueOf(obj.get("apiToken")));

                        try {
                            //扣款操作
                            JSONObject jsonObject = this.handelDeduct(bid, Amount, cookie, String.valueOf(obj.get("apiToken")));
                            //扣款返回的信息
                            JSONObject data = (JSONObject) jsonObject.get("data");
                            if (Objects.isNull(data)) {
                                System.out.println(jsonObject.get("message") + "bid:" + bid + "apiToken:" + String.valueOf(obj.get("apiToken")));
                            } else {
                                Object msg = String.valueOf(data.get("msg"));
                                System.out.println(msg);
                            }

                            /*获取最后一次扣款成功时间*/
                            Date receivedTime = this.taskDetail(bid, cookie);
                            if (!Objects.isNull(receivedTime)) {
                                executionRecordDetails.setReceivedTime(receivedTime);
                            }

                            //当为true时记录成功
                            if (String.valueOf(jsonObject.get("message")).equals("请求成功")) {
                                successTotal++;
                                executionRecordDetailsService.insertExecutionRecordDetails(executionRecordDetails);
                            } else {
                                failTotal++;
                            }
                        } catch (Exception e) {
                            ajaxResult.put("code", "500");
                            ajaxResult.put("msg", "扣款失败，请联系管理员！");
                            e.printStackTrace();
                        }

                        Thread.sleep(2000);
                    }
                    /*失败条数*/
                    executionRecord.setFailTotal(failTotal);
                    /*成功条数*/
                    executionRecord.setSuccessTotal(successTotal);
                    //更新执行记录 总的成功/失败条数
                    executionRecordService.updateExecutionRecord(executionRecord);
                    ajaxResult.put("code", "200");
                    ajaxResult.put("msg", "批量申请成功，共计" + total + "条，申请成功" + successTotal + "条,申请失败" + failTotal + "条。");
                    System.out.println("批量处理成功，共计" + total + "条，申请成功" + successTotal + "条,申请失败" + failTotal + "条。");
                    return ajaxResult;
                } else {
                    ajaxResult.put("code", "200");
                    ajaxResult.put("msg", "获取任务数据为空，请核实是否存在任务数据！");
                    return ajaxResult;
                }

            } else {
                ajaxResult.put("data", null);
                ajaxResult.put("code", 500);
                ajaxResult.put("msg", "导入数据条数为0,请重新导入");
            }

        } catch (Exception e) {
            e.printStackTrace();
            ajaxResult.put("data", null);
            ajaxResult.put("code", 500);
            ajaxResult.put("msg", "导入失败,请重新导入");
        }
        return ajaxResult;
    }

    /* 催记 */
    @PostMapping("/addNotes")
    @ResponseBody
    public AjaxResult addNotes(String cookie) {

        AjaxResult ajaxResult = new AjaxResult();

        JSONArray workList1 = null;

        // 失败条数
        int failuresNum = 0;

        //获取工作台任务列表
        try {
            workList1 = this.getWorkList1(cookie, null);
        } catch (Exception e) {
            e.printStackTrace();
            ajaxResult.put("code", "500");
            ajaxResult.put("msg", "获取用户列表数据失败，请联系管理员！");
            return ajaxResult;
        }

        //当执行任务列表是有效数据时
        if (!Objects.isNull(workList1)) {
            System.out.println("此账号一共查询到" + workList1.size() + "条数据");

            for (Object item : workList1) {
                JSONObject obj = (JSONObject) item;
                // 获取当前订单的第一个联络人
                JSONObject directory = null;
                try {
                    directory = this.queryPhoneDirectory(String.valueOf(obj.get("apiToken")), String.valueOf(obj.get("caseNo")), String.valueOf(obj.get("custId")), cookie);
                    if (Objects.isNull(directory)) {
                        System.out.println("bid:" + obj.get("bid") + "获取联络人为空");
                        //System.out.println("apiToken:" + String.valueOf(obj.get("apiToken")) + "caseNo:" + String.valueOf(obj.get("caseNo"))+ "custId:" + String.valueOf(obj.get("custId")));
                        continue;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    System.out.println("bid:" + obj.get("bid") + "获取联络人异常");
                }

                HashMap<String, Object> map = new HashMap<>();
                map.put("callType", 2);
                map.put("caseNo", String.valueOf(obj.get("caseNo")));
                map.put("collType", "manual");

                /*custId可能传入的数据为 3.45926E+7*/
                double custIdDouble = Double.parseDouble(String.valueOf(obj.get("custId")));
                String custId = String.valueOf(Math.round(custIdDouble));
                map.put("custId", custId);

                map.put("effective", "N");
                map.put("memo", "占线短信已发");
                map.put("oprsCode", 1828);

                /*phoneId可能传入的数据为 3.45926E+7*/
                double phoneIdDouble = Double.parseDouble(String.valueOf(directory.get("phoneId")));
                String phoneId = String.valueOf(Math.round(phoneIdDouble));
                map.put("phoneId", phoneId);

                map.put("phoneTableType", "custPhone");
                map.put("roleCode", "collect");
                map.put("supplier", "qiyou");

                /*taskId可能传入的数据为 3.45926E+7*/
                double taskIdDouble = Double.parseDouble(String.valueOf(obj.get("taskId")));
                String taskId = String.valueOf(Math.round(taskIdDouble));
                map.put("taskId", taskId);

                // 提交催记
                try {
                    JSONObject jsonObject = this.collActionManage(map, cookie);
                    System.out.println("bid:" + obj.get("bid") + ":" + jsonObject.get("message"));
                    if (!"0000".equals(jsonObject.get("code")) || !"请求成功".equals(jsonObject.get("message"))) {
                        failuresNum++;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    System.out.println("bid:" + obj.get("bid") + "提交催记失败");
                    failuresNum++;
                }
            }
        } else {
            ajaxResult.put("code", "200");
            ajaxResult.put("msg", "获取任务数据为空，请核实是否存在任务数据！");
            return ajaxResult;
        }

        System.out.println("催记提交完毕，共计" + workList1.size() + "条，提交失败" + failuresNum + "条");

        return ajaxResult;
    }
}
